<template>
    <div class="tabbar">
        <ul>
            <li v-for="(item, index) in routerList" :key="index" @click="switchTab(item.path)" >
                <span :class="{ active: route.path === item.path }">{{ item.title }}</span>
            </li>
        </ul>
    </div>
</template>
<script setup>
import { ref } from "vue";
// 引入路由
import { useRouter, useRoute } from "vue-router";

const router = useRouter()
const route = useRoute()

const routerList = ref([
    { title: '首页', path: '/home' },
    { title: '商城', path: '/shopping' },
    { title: '直播', path: '/live' },
    { title: '我的', path: '/my' },
])

const switchTab = (path) => {
    // 切换路由
    router.replace(path)
}

</script>
<style scoped>
.tabbar {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 1.5rem;
    z-index: 99;
    background-color: #fff;


}

.tabbar ul {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 100%;
    width: 100%;
    border-top: 1px solid #847b7b;
}

.tabbar ul li {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 25%;
}

.tabbar ul li span {
    font-size: 0.4rem;
}
.active {
    color: red;
}
</style>